package com.inspur.myapplication.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2020/11/18.
 */

public class ShoppingDbHelper extends SQLiteOpenHelper {
    static private final String DB_NAME="shopping.db";
    public ShoppingDbHelper(Context context){
        super(context,DB_NAME,null,2);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        //对数据库进行升级操作
        upateGrade2(sqLiteDatabase);
    }

    private void upateGrade2(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("create table goodstb(goodsid int primary key, goodstitle text, price real,photo text,category text )");
        sqLiteDatabase.execSQL("insert into goodstb(goodsid,goodstitle,price,photo,category)values(1,'goods1',100,'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606276246406&di=404a6677c5202f2cc21dfdefa219eef0&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018-12-15%2F5c14703a0de4c.jpg','shipin')");
        sqLiteDatabase.execSQL("insert into goodstb(goodsid,goodstitle,price,photo,category)values(2,'goods2',110,'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606276246406&di=404a6677c5202f2cc21dfdefa219eef0&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018-12-15%2F5c14703a0de4c.jpg','fangzhi')");
    }

    //private void upateGrade3(SQLiteDatabase sqLiteDatabase){

    //}

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        createUserModel(sqLiteDatabase);
        createGoodsModel(sqLiteDatabase);
        //...
    }

    private void createUserModel(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("create table userInfotb(userid integer primary key autoincrement,username text,password text)");
        sqLiteDatabase.execSQL("insert into userInfotb(username,password)values('admin','123456')");
        //...
    }

    private void createGoodsModel(SQLiteDatabase sqLiteDatabase){
        //sqLiteDatabase.execSQL("");
        //...
    }
    //createOrderModel...
}
